﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Renovation.Filters
{

    /// <summary>
    /// 登录过滤器
    /// </summary>
    public class LoginFilterAttribute :Attribute,IActionFilter
    {
        /// <summary>
        /// 进入业务方法之后
        /// </summary>
        /// <param name="context"></param>
        public void OnActionExecuted(ActionExecutedContext context)
        {
            
        }
        /// <summary>
        /// 进入业务方法之前
        /// </summary>
        /// <param name="context"></param>
        public void OnActionExecuting(ActionExecutingContext context)
        {
            //从session里拿用户的名字
            string name = context.HttpContext.Session.GetString("UserName");
            //name没有值就是没有登录过
            if (string.IsNullOrEmpty(name)) { 
               context.Result = new RedirectResult("/Employee/LoginView");
            }
        }
    }
}
